package com.sptpc.demo1.controller;

import com.sptpc.demo1.model.Category;
import com.sptpc.demo1.model.Drink;
import com.sptpc.demo1.service.ICategoryService;
import com.sptpc.demo1.service.IDrinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class RouterController {
    @Autowired
    public IDrinkService drinkService;
    @Autowired
    public ICategoryService categoryService;

    @GetMapping("/")
    public String home() {
        return "/manage/login";
    }

    @GetMapping("/manage/login")
    public String Login() {
        return "manage/login";
    }

    @GetMapping("/manage/index")
    public String index() {
        return "manage/index";
    }

    //后台欢迎页面
    @GetMapping("/manage/welcome")
    public String welcome() {
        return "manage/welcome";
    }

    //商品管理页面
    @GetMapping("/menu/drink")
    public String Drink() {
        return "drink/index";
    }

    //添加饮品操作
    @GetMapping("/drink/addform")
    public String AddDrink() {
        return "drink/add";
    }

    @GetMapping("/menu/category")
    public String categoryIndex() {
        return "category/index";
    }

    /**
     * 修改饮品操做
     * /drink/updateform?id=2
     */
//    编辑饮品
//     /put /drink/updateform?id=xxx
    @GetMapping("/drink/updateform")
    public ModelAndView upDateDrink(@RequestParam Integer id) {
        ModelAndView mv = new ModelAndView("drink/edit");
        // 按id查询信息
//        Drink build = Drink.builder().id(2)
//                .name("测试饮品")
//                .price(Money.of(CurrencyUnit.of("CNY"), 10.00))
//                .build();
        Drink drink = drinkService.getDrinkById(id);
        mv.addObject("data", drink);
        return mv;
    }

    //新增类型
    @GetMapping("/category/addform")
    public String addCategory() {
        return "category/add";
    }

    //编辑类型
    @GetMapping("/category/updateform")
    public ModelAndView upDateCategory(@RequestParam Integer id) {
        ModelAndView mv = new ModelAndView("category/edit");
        Category category = categoryService.selectbyID(id);
        mv.addObject("data", category);
        return mv;
    }


}
